<?php
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
// DLMan by Shedd Technologies International		  				//
// http://www.dlman.com | info@dlman.com							//
// Copyright 2003 by STI, All rights reserved.						//
// ---------------------------------------------------------------- //
// Usage of this software is governed by the terms of GPL. 	    	//
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//

require_once("global.php");
error_reporting (E_ERROR | E_PARSE);
ob_start();//start content buffer
//SYSTEM SETTINGS
//LICENSING
//TEMPLATES
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
if(isset($sarea)&&$sarea==""){
	//default page
	?>
		<P><FONT face=Verdana>Setting Management</FONT></P>
		<P><FONT face=Verdana>License Management</FONT></P>
		<P><FONT face=Verdana>Template Management</FONT></P>
	<?php
}
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
//system settings
elseif($sarea=="sset"){
	//////////////////////////////////////////////////////////////////////
	if(!isset($edit)){
		$sql="SELECT * FROM ".$config->dt['settings'];
		$result=mysql_query($sql);
		$setting=mysql_fetch_array($result);
	//Main Screen
		?>
		<script language="JavaScript" type="text/javascript">
		function pflHelp(){
			window.open('help_pfl.php?<?php print session_name()."=".session_id()?>', 'newwindow', config='height=400, width=400, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no')
		}//end pflHelp
		
		//show status bar messages
		function statusbar(statusmsg){
			window.status=statusmsg
			return true
		}
		//end show status bar message function
		</script>
		<form action="<?php echo $PHP_SELF."?".$QUERY_STRING; ?>" method="post">
		<input type="hidden" name="edit" value="modify">
		<table width="550" align="center" cellspacing="0" cellpadding="2" border="0">
		<tr>
		    <td colspan="2" bgcolor="#b7b7b7"><b>System Settings</b></td>
		</tr>
		<tr><td colspan="2" bgcolor="black"></td></tr>
		<tr>
		    <td bgcolor="#efefef">
		      <P align=right>System Title&nbsp;</P></td>
		    <td>&nbsp;<input type="text" name="title1" size="45" value="<?php echo $setting["title"]; ?>"></td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">&nbsp;</td>
		    <td>&nbsp;</td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">
		      <P align=right>URL to DLMan<br>(USE trailing slash)&nbsp;</P></td>
		    <td>&nbsp;<input type="text" name="scripturla" size="45" value="<?php echo $setting["script_url"]; ?>"></td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">&nbsp;</td>
		    <td>&nbsp;</td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">
		      <P align=right>Integrated Comunity URL (USE trailing slash)&nbsp;</P></td>
		    <td>&nbsp;<input type="text" name="forum_url1" size="45" value="<?php echo $setting["forum_url"]; ?>"></td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">&nbsp;</td>
		    <td>&nbsp;</td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">
		      <P align=right>Integrated Comunity Name&nbsp;</P></td>
		    <td>&nbsp;<input type="text" name="forum_title1" size="45" value="<?php echo $setting["forum_title"]; ?>"></td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">&nbsp;</td>
		    <td>&nbsp;</td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">
		      <P align=right>Integrated Registration Page (ex. register.php, based off of the comunity URL above)&nbsp;</P></td>
		    <td>&nbsp;<input type="text" name="forum_register1" size="45" value="<?php echo $setting["forum_register"]; ?>"></td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">&nbsp;</td>
		    <td>&nbsp;</td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">
		      <P align=right>Maximum File Size&nbsp;</P></td>
		    <td>&nbsp;<input type="text" name="max_file_size1" size="45" value="<?php echo $setting["max_file_size"]; ?>">&nbsp;bytes</td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">&nbsp;</td>
		    <td>&nbsp;</td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">
		      <P align=right>Sales Department Email Address&nbsp;</P></td>
		    <td>&nbsp;<input type="text" name="sales_address1" size="45" value="<?php echo $setting["sales_address"]; ?>"></td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">&nbsp;</td>
		    <td>&nbsp;</td>
		</tr>
		<?php
			$cols=65;
			$rows=7;
		?>
		<tr>
		    <td bgcolor="#efefef">
		      <P align=right>Successful Payment Validation Email Message&nbsp;</P></td>
		    <td>&nbsp;<textarea cols="<?php print $cols; ?>" rows="<?php print $rows; ?>" class="prefinput" name="validation_go1"><?php echo $setting["validation_go"]; ?></textarea></td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">&nbsp;</td>
		    <td>&nbsp;</td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">
		      <P align=right>Delayed Payment Validation Email Message&nbsp;</P></td>
		    <td>&nbsp;<textarea cols="<?php print $cols; ?>" rows="<?php print $rows; ?>" class="prefinput"  name="validation_delay1"><?php echo $setting["validation_delay"]; ?></textarea></td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">&nbsp;</td>
		    <td>&nbsp;</td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">
		      <P align=right>Password Change Email Message&nbsp;</P></td>
		    <td>&nbsp;<textarea cols="<?php print $cols; ?>" rows="<?php print $rows; ?>" class="prefinput"  name="mail_passchg1"><?php echo $setting["mail_passchg"]; ?></textarea></td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">&nbsp;</td>
		    <td>&nbsp;</td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">
		      <P align=right>Lost Password Email Message&nbsp;</P></td>
		    <td>&nbsp;<textarea cols="<?php print $cols; ?>" rows="<?php print $rows; ?>" class="prefinput"  name="mail_lostpass1"><?php echo $setting["mail_lostpass"]; ?></textarea></td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">&nbsp;</td>
		    <td>&nbsp;</td>
		</tr>
		<!--PAYMENT PROCESSING OPTIONS-->
		<tr>
		    <td bgcolor="black" colspan="2"></td>
		</tr>
		<tr>
		    <td bgcolor="#efefef" colspan="2" align="center"><b>Payment Processing Options</b></td>
		</tr>
		<tr>
		    <td bgcolor="black" colspan="2"></td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">&nbsp;</td>
		    <td>&nbsp;</td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">&nbsp;</td>
			<td><b>PayPal</b> - <a href="http://www.paypal.com" target="_blank">link</a></td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">
		      <P align=right>PayPal Processing&nbsp;</P></td>
		    <td>&nbsp;<input type="radio" name="paypala" value="on" <?php if($setting['paypal_allow']=="on") print "CHECKED"; ?>>Yes&nbsp;&nbsp;<input type="radio" name="paypala" value="off" <?php if($setting['paypal_allow']=="off") print "CHECKED"; ?>>No</td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">&nbsp;</td>
		    <td>&nbsp;</td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">
		      <P align=right>PayPal Account&nbsp;</P></td>
		    <td>&nbsp;<input type="text" name="paypalacct1" size="45" value="<?php echo $setting["paypal_account"]; ?>"></td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">&nbsp;</td>
		    <td>&nbsp;</td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">
		      <P align=right>PayPal Image URL&nbsp;</P></td>
		    <td>&nbsp;<input type="text" name="paypaliurl1" size="45" value="<?php echo $setting["paypal_imageurl"]; ?>"></td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">&nbsp;</td>
		    <td>&nbsp;</td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">
		      <P align=right>PayPal Referral URL&nbsp;</P></td>
		    <td>&nbsp;<input type="text" name="paypalrurl1" size="45" value="<?php echo $setting["paypal_rurl"]; ?>"></td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">&nbsp;</td>
		    <td>&nbsp;</td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">&nbsp;</td>
		    <td><b>2Checkout</b> - <a href="http://www.2checkout.com" target="_blank">link</a></td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">
		      <P align=right>2Checkout Processing&nbsp;</P></td>
		    <td>&nbsp;<input type="radio" name="twoca" value="on" <?php if($setting['2checkout_allow']=="on") print "CHECKED"; ?>>Yes&nbsp;&nbsp;<input type="radio" name="twoca" value="off" <?php if($setting['2checkout_allow']=="off") print "CHECKED"; ?>>No</td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">&nbsp;</td>
		    <td>&nbsp;</td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">
		      <P align=right>2Checkout Seller ID&nbsp;</P></td>
		    <td>&nbsp;<input type="text" name="twocacct1" size="45" value="<?php echo $setting["2checkout_account"]; ?>"></td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">&nbsp;</td>
		    <td>&nbsp;</td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">
		      <P align=right>2Checkout Secret Word&nbsp;</P></td>
		    <td>&nbsp;<input type="text" name="twocsecret1" size="45" value="<?php echo $setting["2checkout_secret"]; ?>"></td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">&nbsp;</td>
		    <td>&nbsp;</td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">
		      <P align=right>2Checkout Demo Mode&nbsp;</P></td>
		    <td>&nbsp;<input type="radio" name="twocd" value="Y" <?php if($setting['2checkout_demo']=="Y") print "CHECKED"; ?>>Yes&nbsp;&nbsp;<input type="radio" name="twocd" value="N" <?php if($setting['2checkout_demo']=="N") print "CHECKED"; ?>>No</td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">&nbsp;</td>
		    <td>&nbsp;</td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">&nbsp;</td>
		    <td><b>VeriSign PayFlow Link</b> - <a href="http://www.verisign.com/products/payflow/link/index.html" target="_blank">link</a></td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">&nbsp;</td>
		    <td><a href="javascript:pflHelp()" onMouseover="return statusbar('Help!')" onMouseout="return statusbar('')">Help on Enabling this Option!</a></td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">
		      <P align=right>PayFlow Link Processing&nbsp;</P></td>
		    <td>&nbsp;<input type="radio" name="pfla1" value="on" <?php if($setting['payflowlink_allow']=="on") print "CHECKED"; ?>>Yes&nbsp;&nbsp;<input type="radio" name="pfla1" value="off" <?php if($setting['payflowlink_allow']=="off") print "CHECKED"; ?>>No</td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">&nbsp;</td>
		    <td>&nbsp;</td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">
		      <P align=right>PayFlow Link Login ID&nbsp;</P></td>
		    <td>&nbsp;<input type="text" name="pflacct1" size="45" value="<?php echo $setting["payflowlink_account"]; ?>"></td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">&nbsp;</td>
		    <td>&nbsp;</td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">
		      <P align=right>PayFlow Link Partner ID&nbsp;</P></td>
		    <td>&nbsp;<input type="text" name="pflpart1" size="45" value="<?php echo $setting["payflowlink_partner"]; ?>"></td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">&nbsp;</td>
		    <td>&nbsp;</td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">&nbsp;</td>
			<td><b>Authorize.Net</b> - <a href="http://www.authorize.net" target="_blank">link</a></td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">
		      <P align=right>Authorize.Net Processing&nbsp;</P></td>
		    <td>&nbsp;<input type="radio" name="authorize1" value="on" <?php if($setting['authorizenet_allow']=="on") print "CHECKED"; ?>>Yes&nbsp;&nbsp;<input type="radio" name="authorize1" value="off" <?php if($setting['authorizenet_allow']=="off") print "CHECKED"; ?>>No</td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">&nbsp;</td>
		    <td>&nbsp;</td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">
		      <P align=right>Account Login&nbsp;</P></td>
		    <td>&nbsp;<input type="text" name="authorizenet_login1" size="45" value="<?php echo $setting["authorizenet_login"]; ?>"></td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">&nbsp;</td>
		    <td>&nbsp;</td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">
		      <P align=right>Transaction Key&nbsp;</P></td>
		    <td>&nbsp;<input type="text" name="authorizenet_transkey1" size="45" value="<?php echo $setting["authorizenet_transkey"]; ?>"></td>
		</tr>
		<tr><td colspan="2" bgcolor="black"></td></tr>
		<tr>
		    <td colspan="2" bgcolor="#b7b7b7">
		      <P align=center><input class="but" type="submit" value="Edit Settings" class="button"></P></td>
		</tr>
		</table>
		<input type="hidden" name="edit" value="true">
		</form>
		<?php
	}
	//////////////////////////////////////////////////////////////////////
	//Make database changes
	else{
		$base_path=addslashes($base_path);
		$sqlarray=array(
			"UPDATE ".$config->dt['settings']." SET title='".addslashes($title1)."';",
			"UPDATE ".$config->dt['settings']." SET script_url='".$scripturla."';",
			"UPDATE ".$config->dt['settings']." SET forum_url='".$forum_url1."';",
			"UPDATE ".$config->dt['settings']." SET forum_title='".addslashes($forum_title1)."';",
			"UPDATE ".$config->dt['settings']." SET forum_register='".$forum_register1."';",
			"UPDATE ".$config->dt['settings']." SET max_file_size='".$max_file_size1."';",
			"UPDATE ".$config->dt['settings']." SET sales_address ='".$sales_address1."';",
			"UPDATE ".$config->dt['settings']." SET validation_go='".addslashes($validation_go1)."';",
			"UPDATE ".$config->dt['settings']." SET validation_delay='".addslashes($validation_delay1)."';",
			"UPDATE ".$config->dt['settings']." SET mail_passchg='".addslashes($mail_passchg1)."';",
			"UPDATE ".$config->dt['settings']." SET mail_lostpass='".addslashes($mail_lostpass1)."';",
			"UPDATE ".$config->dt['settings']." SET paypal_allow='".$paypala."';",
			"UPDATE ".$config->dt['settings']." SET paypal_account='".$paypalacct1."';",
			"UPDATE ".$config->dt['settings']." SET paypal_imageurl='".$paypaliurl1."';",
			"UPDATE ".$config->dt['settings']." SET paypal_rurl='".$paypalrurl1."';",
			"UPDATE ".$config->dt['settings']." SET 2checkout_allow='".$twoca."';",
			"UPDATE ".$config->dt['settings']." SET 2checkout_account='".$twocacct1."';",
			"UPDATE ".$config->dt['settings']." SET 2checkout_demo='".$twocd."';",
			"UPDATE ".$config->dt['settings']." SET 2checkout_secret='".$twocsecret1."';",
			"UPDATE ".$config->dt['settings']." SET payflowlink_allow='".$pfla1."';",
			"UPDATE ".$config->dt['settings']." SET payflowlink_account='".$pflacct1."';",
			"UPDATE ".$config->dt['settings']." SET payflowlink_partner='".$pflpart1."';",
			"UPDATE ".$config->dt['settings']." SET authorizenet_allow='".$authorize1."';",
			"UPDATE ".$config->dt['settings']." SET authorizenet_login='".$authorizenet_login1."';",
			"UPDATE ".$config->dt['settings']." SET authorizenet_transkey='".$authorizenet_transkey1."';",
		);
		//Process Query
		
		$err=false;
		foreach($sqlarray as $sql){
			$result="";
			if(!$result=mysql_query($sql)){
				print "<p>Error in updating data!<br>";
				print mysql_error();
				print '<br><a href="';
				print $PHP_SELF;
				print '?action=settings">Click Here to try again</a><br><br>';
				print "$sql</p>";
				$err=true;
			}//end error
		}//end loop
		if($err!=true){
			?><br><br><div align="center">
			<STRONG><FONT face=Verdana size=2>All settings have been updated.</FONT></STRONG>
			<?php
				print '<br><br><a href="';
				print $PHP_SELF."?".$QUERY_STRING;
				print '">Click Here to Continue</a></div><br><br>';
		}//end no error
		else{
			print "Error in updating information.  Please try again.";
		}
	}
	//////////////////////////////////////////////////////////////////////
}
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
// LICENSE
elseif($sarea=="license"){
//////////////////////////////////////////////////////////////////////
	//ADD LICENSE
	if($laction=="alic"){
		if(!isset($sa)){
			//show license form
			print license_form($this_variable_should_be_undefined,$sarea);
		}//end subaction is not set
		else{
			/////////////////////////
			//add info to license table
			$result=mysql_query("INSERT INTO ".$config->dt['license']." (id, data, title) VALUES ('', '$data', '$lictitle')");
			if(!$result){
				die("<b>ADDITION FAILED:</b> Error adding data to table!<br>".mysql_error());
			}
			else{
				print "Entry successful!<br>";
				$id= mysql_insert_id();
			    print "<p>This license has the following Database ID: <b>$id</b>";
			}
			/////////////////////////
		}//end subaction is set
	}//end add license
	//////////////////////////////////////////////////////////////////////
	//MANAGE LICENSES
	elseif($laction=="mlic"){
		if(!isset($saction)){//check for subaction
			//output list of licenses
			$sql="SELECT * FROM ".$config->dt['license'];
			$result=mysql_query($sql);
			//check for success
			if(!$result){
				print "Failure to Pull License Data";
			}
			else{
			?>
			<table cellpadding="0" cellspacing="0" border="0" width="100%">
			<tr>
				<td>
					<table cellpadding="3" cellspacing="1" border="0" width="100%">
						<tr>
							<td colspan="2"><b>Manage Licenses</b></td>
							<tr>
								<td width="30%"><p>Select License:</p></td>
								<td width="70%">
									<table border="0">
										<tr>	
											<form action="<?php print $PHP_SELF; ?>" method="post">
											<td>
												<input type="hidden" name="sarea" value="license">
												<input type="hidden" name="laction" value="mlic">
												<input type="hidden" name="saction" value="manage">
												<select name="id">
												<?php
													while($value=mysql_fetch_array($result)){
														?>
										   					<option value="<?php print $value['id']; ?>"><?php print $value['title']; ?></option>
														<?php
													}
												?>
										   		</select>
											</td>
											<td>
												<input type="submit" value="Select License" class="button">
											</td>
										   </form>
										</tr>
									</table>
								</td>
							</tr>
					</table>
				</td>
			</tr>
			</table>
			<?php
			}//end else
		}//end subaction NOT set
		/////////////////////////
		elseif($saction=="manage"){
			//check for id
			if(!isset($id)){
				die("Invalid ID");
			}
			//show license form
			print license_form($id,$sarea);
			?>
			<center>
			<script language="JavaScript" type="text/javascript">
			<!--Hide Script from Old Browsers
			//Check to make sure that the user really wants to delete user
			function doVerify(closerequest){
				var txt="Are you sure that you want to delete this license?  THIS ACTION CAN NOT BE UNDONE!"
				if(!confirm(txt)){
					alert("License was not deleted!");
					return false;
				}
				else{
					return true;
				}
			}
			//End Hide-->
			</script>
			<form method="post" action="<?php print $PHP_SELF; ?>" onsubmit="return doVerify(this);">
				<input type="hidden" name="action" value="cc_delete">
				<input type="hidden" name="thetype" value="<?php print $config->dt['license']; ?>">
				<input type="hidden" name="idfield" value="id">
				<input type="hidden" name="idval" value="<?php print $id; ?>">
				<input type="hidden" name="urlback" value="<?php print "$PHP_SELF?sarea=$sares&laction=$laction&saction=$saction"; ?>">
				<input type="hidden" name="confirm" value="Yes">
				<input type="submit" value="Delete">
			</form>
			</center>
			<?php
		}//end manage sub action
	}//end manage licenses
	//////////////////////////////////////////////////////////////////////
	//MAKE CHANGES TO LICENSE
	elseif($laction=="mlic-edit"){
		//check for id
		if(!isset($oid)){
			die("Invalid ID!");
		}
		
		//update info in license table
		$sqlcode=array();
		$sqlcode[0]="UPDATE ".$config->dt['license']." SET title='$lictitle' WHERE id = '$oid';";
		$sqlcode[1]="UPDATE ".$config->dt['license']." SET data='$data' WHERE id = '$oid';";
		for($i=2;$i<7;$i++){
			$c=($i-1);
			$act="activated_$c";
			$nme="name_$c";
			$tpe="type_$c";
			$html="html_$c";
			$sqlcode[$i]="UPDATE ".$config->dt['license']." SET activated_$c='".$$act."', name_$c='".$$nme."', type_$c='".$$tpe."', html_$c='".htmlspecialchars($$html)."' WHERE id = '$oid';";
		}
		
		$err=false;
		foreach($sqlcode as $sql){
			$result="";
			if(!$result=mysql_query($sql)){
				print "<p>Error in updating data!<br>";
				print mysql_error();
				print '<br><a href="';
				print $PHP_SELF;
				print '?sarea=license&laction=mlic">Click Here to try again</a><br><br>';
				print "$sql</p>";
				$err=true;
			}//end error
		}//end loop
		
		if($err!=true){
		?><br><br><div align="center">
		<STRONG><FONT face=Verdana size=2>Data has been updated.</FONT></STRONG>
		<?php
			print '<br><br><a href="';
			print $PHP_SELF;
			print '?sarea=license&laction=mlic">Click Here to Continue</a></div><br><br>';
		}//end no error
		else{
			print "Error in updating information.  Please try again.";
		}
	}//end Manage License - Edit
}//end sarea=license
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
// TEMPLATES
elseif($sarea=="templates"){
//////////////////////////////////////////////////////////////////////
	//SHOW LIST OF TEMPLATES
	if($taction!="medit")
		$temp_dat=template_list($template,$sarea);
	//DISPLAY TEMPLATE BOX
	if($taction=="edit"){
		//$temp_con=str_replace('$','\\$',"$temp_con");
		?>
	<style>
		.template_textarea {
			width: 100%;
		}
	</style>
	<form action="<?php print $PHP_SELF; ?>" method="post">
	<hr size=1 color=black>
		<input type="hidden" name="sarea" value="<?php print $sarea; ?>">
		<input type="hidden" name="taction" value="medit">
		<input type="hidden" name="oid" value="<?php print $temp_dat[0]; ?>">
	   	<table cellpadding="0" cellspacing="0" border="0" width="100%">
	   		<tr>
	   			<td>
	   				<table cellpadding="3" cellspacing="1" border="0" width="100%">
	   					<tr>
	   						<td>
	   							<textarea name="updated_template" cols="100" rows="25" wrap="off" class="prefinput"><?php print $temp_dat[1]; ?></textarea>
	   							<tr>
	   								<td colspan="1" align="center">	&nbsp;
	   								   <input type="submit" value="Save Changes" class="button">&nbsp;
	   								</td>
	   							</tr>
	   				</table>
	   			</td>
	   		</tr>
	   	</table>
		<hr size=1 color=black>
	</form>
		<?php
	}//end taction=edit
	//MAKE THE EDITS
	elseif($taction=="medit"){
		$sql="UPDATE ".$config->dt['templates']." SET template='$updated_template' WHERE id='$oid'";
		$result=mysql_query($sql);
		if(!$result){
			print "Error updating data!<br>$sql<br>";
			print mysql_error();
		}
		else{
			$redir="<script language=\"javascript\">window.location=\"admin.php?sarea=templates&taction=edit&template=$oid&message=Update+Successful\";</script>\n";
			print "Update Successful!";
			print $redir;
		}
	}//end taction=medit
//////////////////////////////////////////////////////////////////////
}//end templates section
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
$content=ob_get_contents();//store content to global buffer var
ob_end_clean();
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
//FUNCTIONS
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
/*
	Generate the form for add/manage license.
	$id can be undefined
	$sarea is the Settings Area value
*/
function license_form($id,$sarea){
	global $config,$PHP_SELF;
	ob_start();//start content buffer
	if(isset($id)){
		$sql="SELECT * FROM ".$config->dt['license']." WHERE id='$id';";
		$result=mysql_query($sql);
		//check for success
		if(!$result){
			print "Failure to Pull License Data";
		}
		$value=mysql_fetch_array($result);
	}
	?>
		<form action="<?php print $PHP_SELF; ?>" method="post" enctype="multipart/form-data" name="license_form">
			<input type="hidden" name="sarea" value="<?php print $sarea; ?>">
			<?php
			//edit mode
			if(!isset($id)){
				?>
					<input type="hidden" name="laction" value="alic">
					<input type="hidden" name="sa" value="upload">
				<?php
			}
			//new mode
			else{
				?>
					<input type="hidden" name="laction" value="mlic-edit">
				<?php
			}
			?>
			<input type="hidden" name="oid" value="<?php print $id; ?>">
			<table width="500" align="center" cellspacing="0" cellpadding="2" border="0">
				<tr>
			  			<td colspan="2" align="center">
							<?php
							//manage license
							if(isset($id)){
								?>
									<font face="Verdana" size="3"><b>Manage <i><?php print $value['title']; ?></i> License</b></font>
								<?php
							}
							//add license
							else{
								?>
									<font face="Verdana" size="3"><b>Add License</b></font>
								<?php
							}
							?>
						</td>
				</tr>
				<tr>
				    <td align="right"><b>Title:</b></td>
				    <td><input type="text" name="lictitle" value="<?php print $value['title']; ?>" class="prefinput" size="25"></td>
				</tr>
				<tr>
					<td align="right" valign="top"><b>License Data:</b><br></td>
					<td><textarea cols="90" rows="20" name="data" class="prefinput"><?php print $value['data']; ?></textarea></td>
				</tr>
				<tr>
					<td colspan="2"><?php if(isset($id)){ custom_items($value); } else { print "After Adding This License, Use the Management Tool to Edit Custom Fields."; } ?></td>
				</tr>
				<tr>
			  			<td colspan="2" align="center"><input type="submit" value="<?php if(isset($id)) print "Edit"; else print "Add"; ?>">&nbsp;&nbsp;<input type="Reset"></td>
				</tr>
			</table>
		</form>
	<?php
	$content=ob_get_contents();//store content to global buffer var
	ob_end_clean();
	return $content;
}//end function license_form
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
/*
	Generate the form portion for custom items.
	$value is the parameter, array set from database record
		can be undefined
*/
function custom_items($value){
	//loop thorugh for 5 custom entries
	print '<hr size="1" color="Black">';
	for($i=1;$i<6;$i++){
		?>
			<!--CUSTOM ITEM <?php print $i; ?>-->
			<a name="<?php print $i; ?>"></a>
			<table cellspacing="0" cellpadding="2" border="0">
			<tr>
				<td colspan="2"><b>Custom Field <?php print $i; ?></b></td>
			</tr>
			<tr>
			    <td>Activated:&nbsp;</td>
			    <td>
				<?php
				///////////////////////////////////////////////////////
					if(isset($value)){
						//existing true
						if($value["activated_$i"]=="true"){
							?>
								<INPUT type=radio class="prefinput" value=true name=activated_<?php print $i; ?> checked>Yes&nbsp;&nbsp;<input type="radio" class="prefinput" name="activated_<?php print $i; ?>" value="false">No
							<?php
						}
						//existing false
						else{
							?>
								<INPUT type=radio class="prefinput" value=true name=activated_<?php print $i; ?>>Yes&nbsp;&nbsp;<input type="radio" class="prefinput" name="activated_<?php print $i; ?>" value="false" checked>No
							<?php
						}
					}
					//no existing
					else{
						?>
							<INPUT type=radio class="prefinput" value=true name=activated_<?php print $i; ?>>Yes&nbsp;&nbsp;<input type="radio" class="prefinput" name="activated_<?php print $i; ?>" value="false" checked>No
						<?php
					}
				///////////////////////////////////////////////////////
				?>
				</td>
			</tr>
			<tr>
			    <td>Name:&nbsp;</td>
			    <td><input type="text" class="prefinput" name="name_<?php print $i; ?>" size="25" value="<?php print $value["name_".$i]; ?>"></td>
			</tr>
			<script language="JavaScript" type="text/javascript">
			function SampleCode<?php print $i; ?>(ftype){
			<?php
				$text_code='<input type="text" name="name_'.$i.'" value="{v'.$i.'}" size="25" maxlength="100">';
				$textbox_code='<textarea cols="#cols" rows="#rows" name="name_'.$i.'">{v'.$i.'}</textarea>';
				$radio_code='<input type="radio" name="name_'.$i.'" value="value" {value-v'.$i.'}>caption';
				$select_code='<select name="name'.$i.'" size="1"><option value="value" {value-v'.$i.'}>option text</option></select>';
				$cb_code='<input type="checkbox" name="name_'.$i.'" value="value" {value-v'.$i.'}>caption';
			?>
				if((document.license_form.html_<?php print $i; ?>.value!="")&&!window.confirm("Do you want to replace the existing HTML code for this item?")){
						alert("Action Canceled!");
						return false;
				}
				else{
					//TEXT CODE
					if(ftype=='text'){
						document.license_form.html_<?php print $i; ?>.value='<?php print $text_code; ?>';
						document.license_form.html_<?php print $i; ?>.focus();
					}
					//TEXTBOX CODE
					if(ftype=='textbox'){
						document.license_form.html_<?php print $i; ?>.value='<?php print $textbox_code; ?>';
						document.license_form.html_<?php print $i; ?>.focus();
					}
					//RADIO CODE
					if(ftype=='radio'){
						document.license_form.html_<?php print $i; ?>.value='<?php print $radio_code; ?>';
						document.license_form.html_<?php print $i; ?>.focus();
					}
					//SELECT
					if(ftype=='select'){
						document.license_form.html_<?php print $i; ?>.value='<?php print $select_code; ?>';
						document.license_form.html_<?php print $i; ?>.focus();
					}
					//CHECKBOX
					if(ftype=='cb'){
						document.license_form.html_<?php print $i; ?>.value='<?php print $cb_code; ?>';
						document.license_form.html_<?php print $i; ?>.focus();
					}
					return true
				}
			}//end SampleCode
			
			//show status bar messages
			function statusbar(statusmsg){
				window.status=statusmsg
				return true
			}
			//end show status bar message function
			</script>
			<tr>
			    <td>Type:&nbsp;</td>
			    <td>
					<select name="type_<?php print $i; ?>" class="prefinput" size="1">
						<option value="text" <?php if($value["type_".$i]=="text")print "SELECTED"; ?>>Text</option>
						<option value="textbox" <?php if($value["type_".$i]=="textbox")print "SELECTED"; ?>>Textbox</option>
						<option value="radio" <?php if($value["type_".$i]=="radio")print "SELECTED"; ?>>Radio</option>
						<option value="select" <?php if($value["type_".$i]=="select")print "SELECTED"; ?>>Select</option>
						<option value="cb" <?php if($value["type_".$i]=="cb")print "SELECTED"; ?>>Checkbox</option>
					</select>
				</td>
			</tr>
			<tr>
			    <td>HTML:&nbsp;<br>Use <b>name_<?php print $i; ?></b> as the name attribute.<br><a onMouseover="return statusbar('Insert Sample Code')" onMouseout="return statusbar('')" onclick='return SampleCode<?php print $i; ?>(document.license_form.type_<?php print $i; ?>.value)' href="#<?php print $i; ?>">Sample Code</a></td>
			    <td><textarea class="prefinput" cols="50" rows="4" name="html_<?php print $i; ?>"><?php print $value["html_".$i]; ?></textarea></td>
			</tr>
			</table>
			<hr size="1" color="Black">
			<!--end CUSTOM ITEM <?php print $i; ?>-->
		<?php
	}
}//end function custom_items
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
/*
	Generate the list of templates.
	Returns array(TEMPLATE ID,TEMPLATE CONTENT)
*/
function template_list($template,$sarea){
global $PHP_SELF,$config;
?>
<table cellpadding="0" cellspacing="0" border="0" width="100%">
	<tr>
		<td>
			<table cellpadding="3" cellspacing="1" border="0" width="100%">
				<tr>
					<td colspan="2"><b>Edit Templates</b></td>
					<tr>
						<td width="30%"><p>Select Template:</p></td>
						<td width="70%">
							<table border="0">
								<tr>									      
								   <form method="post" action="<?php print $PHP_SELF; ?>">
								   	<td>
								   	   <input type="hidden" name="taction" value="edit">
									   <input type="hidden" name="sarea" value="<?php print $sarea; ?>">
								   		<select name="template">
										<?php
											global $temp_con;
											$sql="SELECT * FROM ".$config->dt['templates'];
											$result=mysql_query($sql);
											while($value=mysql_fetch_array($result)){
												?>
								   					<option value="<?php print $value['id']; ?>" <?php if($value['id']==$template) print "SELECTED"; ?>><?php print $value['name']; ?></option>
												<?php
												if($value['id']==$template){
													$temp_con=$value[template];
													$temp_id=$value[id];
												}
											}
										?>
								   		</select>
								   	</td>
								   	<td>
								   	   <input type="submit" value="Select Template" class="button">
								   	</td>
								   </form>
								</tr>
							</table>
						</td>
					</tr>
			</table>
		</td>
	</tr>
</table>
<?php
	if(isset($temp_con)){
		$retarray=array($temp_id,$temp_con);
		return $retarray;
	}
}//end function template list
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
?>